﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DanhMuc_DanhSachDonViGiaiThe : System.Web.UI.Page
{
    _dbDataContext _db = new _dbDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }
    private void BindGrid()
    {
        string madonvi = MemberShip_ASP.GetMaDonViFromUserName(Page.User.Identity.Name);//lay ma don vi thuoc username dang nhap
        var val = _db.tblCoSoDoans.Where(r => r.TrucThuoc.Trim() == madonvi && r.GiaiThe == true).ToList();
        grid.DataSource = val.ToList();
        grid.DataBind();
    }
    protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "cmdGiaiTheCSD")
        {
            pncontent.Visible = false;
            pndetail.Visible = true;
            BindText(e.CommandArgument.ToString().Trim());
        }
        else if (e.CommandName == "cmdXoaGiaiTheCSD")
        {
            var item = _db.tblCoSoDoans.Single(r => r.MaDonVi.Trim() == e.CommandArgument.ToString().Trim());
            try
            {
                _db.tblCoSoDoans.DeleteOnSubmit(item);
                _db.SubmitChanges();
                BindGrid();
            }
            catch { }
        }
    }
    protected void btnclose_Click(object sender, EventArgs e)
    {
        pncontent.Visible = true;
        pndetail.Visible = false;
    }
    protected void BindText(string madonvi)
    {
        var item = _db.tblGiaiTheDonViDoans.Single(r => r.MaDonVi.Trim() == madonvi);
        txtSoQuyetDinh.Text = item.QuyetDinhSo;
        txtNgayGiaiThe.Text = string.Format("{0:dd/MM/yyyy}",item.NgayGiaiThe);
        txtLyDo.Text = item.LyDoGiaiThe;
    }
}